<template>
  <div className="user-container">
    <!-- 导航栏 -->
    <van-nav-bar title="黑马头条号" left-arrow/>
    <!-- /导航栏 -->

    <!-- 用户信息 -->
    <div className="user-info-container">
      <div className="row1">
        <van-image
          className="col1"
          fit="cover"
          round
          :src="user.photo"
          @click="onPreview(user.photo)"
        />
        <div className="col2">
          <div className="row1">
            <div className="item">
              <div className="count">{{ user.art_count }}</div>
              <div className="text">发布</div>
            </div>
            <div className="item">
              <div className="count">{{ user.follow_count }}</div>
              <div className="text">关注</div>
            </div>
            <div className="item">
              <div className="count">{{ user.fans_count }}</div>
              <div className="text">粉丝</div>
            </div>
            <div className="item">
              <div className="count">{{ user.like_count }}</div>
              <div className="text">获赞</div>
            </div>
          </div>
          <div className="action">
            <van-button
              type="primary"
              size="small"

            >私信
            </van-button>
            <van-button
              type="default"
              size="small"
            >编辑资料
            </van-button>
          </div>
        </div>
      </div>
      <div className="intro-wrap">
        <div>
          <span>认证：</span>
          <span>{{ user.certi }}</span>
        </div>
        <div>
          <span>简介：</span>
          <span>{{ user.intro }}</span>
        </div>
      </div>
    </div>
    <!-- /用户信息 -->

    <!-- 文章列表 -->
    <!-- /文章列表 -->
  </div>
</template>

<script>
import { getUserById } from '@/api/user'
import { getArticlesByUser } from '@/api/article'

export default {
  name: 'UserPage',
  components: {},
  props: {},
  data () {
    return {
      user: {},
      list: [], // 列表数据
      loading: false, // 控制上拉加载更多的 loading
      finished: false, // 控制是否加载结束了
      page: 1 // 获取下一页数据的页码
    }
  },
  computed: {},
  watch: {},
  created () {
    this.loadUser()
  },
  mounted () {
  },
  methods: {
    async loadUser () {
      try {
        const { data } = await getUserById(this.$route.params.userId)
        this.user = data.data
      } catch (err) {
        console.log(err)
        this.$toast('获取用户数据失败')
      }
    },
    async onLoad () {
      // 1. 请求获取数据
      const { data } = await getArticlesByUser(this.$route.params.userId, {
        page: this.page,
        per_page: 20
      })

      const { results } = data.data
      this.list.push(...results)

      this.loading = false

      if (results.length) {
        this.page++
      } else {
        this.finished = true
      }
    }
  }

}
</script>

<style scoped lang="less">
.user-container {
  font-size: 14px;

  .user-info-container {
    padding: 12px;
    background-color: #fff;
    margin-bottom: 10px;

    > .row1 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;

      .item {
        text-align: center;

        .text {
          font-size: 12px;
        }
      }

      > .col1 {
        width: 80px;
        height: 80px;
      }

      > .col2 {
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        width: 70%;
        height: 80px;
        padding: 0 12px;

        > .row1 {
          display: flex;
          justify-content: space-between;
        }

        .action {
          display: flex;
          justify-content: space-between;

          .van-button {
            width: 45%;
          }
        }
      }
    }
  }
}
</style>
